home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TestLogEngine.c
-
- Contains: A program to display information logged to the STREAMS log module.
-
- Written by: Quinn "The Eskimo!"
-
- Copyright: Copyright © 1998-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/23/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
- #define qDebug 1
-
- /////////////////////////////////////////////////////////////////////
- // Pick up the standard C stuff.
-
- #include <stdio.h>
- #include <string.h>
-
- /////////////////////////////////////////////////////////////////////
- // Pick up standard OT APIs.
-
- #include <OpenTptInternet.h>
-
- /////////////////////////////////////////////////////////////////////
- // Pick up low-level OT APIs.
-
- #include <OpenTptClient.h>
- #include <OTDebug.h>
- #include <strlog.h>
- #include <stropts.h>
- #include <mistream.h>
-
- /////////////////////////////////////////////////////////////////////
- // Pick up the symbolic name of the various OT modules.
-
- #include <modnames.h>
-
- /////////////////////////////////////////////////////////////////////
- // Pick up the log engine prototypes.
-
- #include "LogEngine.h"
-
- /////////////////////////////////////////////////////////////////////
- // OTDebugStr is not defined in any OT header files, but it is
- // exported by the libraries, so we define the prototype here.
-
- extern pascal void OTDebugStr(const char* str);
-
- /////////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////////
-
- static pascal void PrintLogEntry(LogEntryPtr thisEntry, void *refCon)
- {
- #pragma unused(refCon)
- #pragma unused(thisEntry)
-
- printf("••• got message “%s”\n", ((char *) thisEntry) + sizeof(LogEntry));
- }
-
- /////////////////////////////////////////////////////////////////////
-
- static void PrintHelp(void)
- {
- printf("s) start/stop logging\n");
- printf("l) log something\n");
- printf("L) log 10 somethings\n");
- printf("i) idle the kernel (don't ask why you have to do this!)\n");
- printf("p) print new log entries\n");
- printf("q) quit\n");
- printf("?) print help\n");
- printf("\n");
- }
-
- extern void main(void)
- {
- OSStatus err;
- Boolean quitNow;
- char command[256];
- int i;
-
- printf("Hello Cruel World\n");
-
- err = InitOpenTransport();
- if (err == noErr) {
-
- PrintHelp();
- quitNow = false;
- do {
- printf("Enter command:\n");
- gets(command);
- switch (command[0]) {
- case '?':
- PrintHelp();
- break;
- case 's':
- if ( ! LoggingActive() ) {
- printf("StartLogging\n");
- fflush(stdout);
- err = StartLogging(true, 0, nil);
- if (err != noErr) {
- printf("Error starting logging %ld\n", err);
- err = noErr;
- }
- } else {
- printf("StopLogging\n");
- fflush(stdout);
- StopLogging();
- }
- break;
- case 'i':
- OTIdle();
- break;
- case 'p':
- ForEachNewLogEntry(PrintLogEntry, nil);
- break;
- case 'q':
- quitNow = true;
- break;
- case 'l':
- printf("Calling strlog\n");
- strlog(1, 2, 3, SL_TRACE | SL_ERROR, "Hello Cruel World!");
- break;
- case 'L':
- for (i = 0; i < 10; i++) {
- printf("Calling strlog\n");
- strlog(1, 2, 3, SL_TRACE | SL_ERROR, "Hello Cruel World!");
- }
- break;
- case '!':
- for (i = 0; i < 32000; i++) {
- // OTIdle();
- strlog(1, 2, 3, SL_TRACE | SL_ERROR, "Hello Cruel World!");
- if ( (i % 100) == 0) {
- printf(".");
- fflush(stdout);
- }
- }
- break;
- default:
- printf("Huh?\n");
- break;
- }
- } while ( ! quitNow );
-
- if ( LoggingActive() ) {
- printf("StopLogging\n");
- fflush(stdout);
- StopLogging();
- }
-
- CloseOpenTransport();
- }
-
- if (err == noErr) {
- printf("Success!\n");
- } else {
- printf("Failed with error %ld.\n", err);
- }
- }